<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .v_code {
            width: 600px;
            margin: 0 auto;
        }
        .v_code>input {
            width: 60px;
            height: 36px;
            margin-top: 10px;
        }
        .code_show {
            /*overflow: hidden;*/
        }
		.code_show::after {
			clear: both;
			height:00px;
			background:yellow;
			display: block;
			content: "";
		}
        .code_show span {
            display: block;
            float: left;
            margin-bottom: 10px;
        }

        .code_show a {
            display: block;
            float: left;
            margin-top: 10px;
            margin-left: 10px;
        }

        .code {
            font-style: italic;
            background-color: #f5f5f5;
            color: blue;
            font-size: 30px;
            letter-spacing: 3px;
            font-weight: bolder;
            float: left;
            cursor: pointer;
            padding: 0 5px;
            text-align: center;
        }

        #inputCode {
            width: 100px;
            height: 30px;
        }
        
        a {
            text-decoration: none;
            font-size: 12px;
            color: #288bc4;
            cursor: pointer;
        }

        a:hover {
            text-decoration: underline;
        }

    </style>
		<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
</head>

<body>
    <div class="v_code">
        <div class="code_show">
            <span class="code" id="checkCode"></span>
            <a id="linkbt">看不清换一张</a>
        </div>
        <div class="input_code">
            <label for="inputCode">验证码：</label>
            <input type="text" id="inputCode" />
            <span id="text_show"></span>
        </div>
        <input id="Button1" type="button" value="确定" />
    </div>
    <script>
		$(document).ready(function(){
			let res = getCode();
			
            function getCode(){
                var arr = [];
				for(let i = 0; i < 10; ++i){
					arr.push(i + "");
				}
				for(let i=0;i<25;i++){
					arr.push(String.fromCharCode((65+i)));
				}
                var str = '';
                for(let i = 0; i < 6; i++){
					let num = Math.round((Math.random() * (arr.length-1)));
                    str += arr[num];
                }
                return str;
            }
			
			$('#checkCode').text(res);
			$('#linkbt').click(() =>{
				$('#checkCode').text(getCode());
			});
			
			$('#Button1').click(() =>{
				let userinput = $('#inputCode').val();
				let code = $('#checkCode').text();
				if(userinput === code)
					location.href = 'https://www.baidu.com';
				else
					$('#linkbt').click();
			});
		});

    </script>
</body>

</html>